package com.aspose.cells;

class zamp {
   private byte[] a;
   private zjr b;
   private zrf c;

   public zamp() {
      this.b = zjq.a(zcgd.b, zcgg.c);
      this.c = zrd.a(zcgh.a);
      this.a = new byte[16];
   }

   public void a(short[] var1, byte[] var2) {
      byte[] var3 = new byte[64];
      int var4 = 0;

      for(byte var5 = 16; var4 < var5 && var1[var4] != 0; ++var4) {
         var3[2 * var4] = (byte)(var1[var4] >>> 0 & 255);
         var3[2 * var4 + 1] = (byte)(var1[var4] >>> 8 & 255);
      }

      var3[2 * var4] = -128;
      var3[56] = (byte)(var4 << 4);
      zrd.a(this.c, var3, 0, var3.length);
      zrd.a(this.c, var3, 16);

      for(var4 = 0; var4 < 16; ++var4) {
         zrd.a(this.c, var3, 0, 5);
         zrd.a(this.c, var2, 0, 16);
      }

      var3[16] = -128;

      for(var4 = 17; var4 < var3.length; ++var4) {
         var3[var4] = 0;
      }

      var3[56] = -128;
      var3[57] = 10;
      zrd.a(this.c, var3, 16, var3.length - 16);
      zrd.a(this.c, this.a, this.a.length);
   }

   public void a(byte[] var1, byte[] var2) {
      byte[] var3 = new byte[64];
      int var4 = 0;

      for(byte var5 = 16; var4 < var5 && (var1[2 * var4] != 0 || var1[2 * var4 + 1] != 0); ++var4) {
         var3[2 * var4] = (byte)(var1[2 * var4] & 255);
         var3[2 * var4 + 1] = (byte)(var1[2 * var4 + 1] & 255);
      }

      var3[2 * var4] = -128;
      var3[56] = (byte)(var4 << 4);
      zrd.a(this.c, var3, 0, var3.length);
      zrd.a(this.c, var3, 16);

      for(var4 = 0; var4 < 16; ++var4) {
         zrd.a(this.c, var3, 0, 5);
         zrd.a(this.c, var2, 0, 16);
      }

      var3[16] = -128;

      for(var4 = 17; var4 < var3.length; ++var4) {
         var3[var4] = 0;
      }

      var3[56] = -128;
      var3[57] = 10;
      zrd.a(this.c, var3, 16, var3.length - 16);
      zrd.a(this.c, this.a, this.a.length);
   }

   public void a(byte[] var1, byte[] var2, byte[] var3) {
      this.a(0);
      zjq.b(this.b, var1, 0, 16, var2, 0, 16);
      byte[] var4 = new byte[64];
      System.arraycopy(var1, 0, var4, 0, var1.length);
      var4[16] = -128;

      for(int var5 = 17; var5 < var4.length; ++var5) {
         var4[var5] = 0;
      }

      var4[56] = -128;
      byte[] var6 = new byte[16];
      zrd.a(this.c, var4, 0, var4.length);
      zrd.a(this.c, var6, var6.length);
      zjq.b(this.b, var6, 0, var6.length, var4, 0, var4.length);
      System.arraycopy(var4, 0, var3, 0, 16);
   }

   public void b(byte[] var1, byte[] var2) {
      if (!this.a(0)) {
         com.aspose.cells.a.e.zf.a("Cipher initialization failed.");
      }

      byte[] var3 = new byte[16];
      byte[] var4 = new byte[64];
      if (!this.a(0)) {
         ;
      }

      zjq.a((zjr)this.b, var1, 0, 16, var4, 0, var4.length);
      var4[16] = -128;

      for(int var5 = 17; var5 < var4.length; ++var5) {
         var4[var5] = 0;
      }

      var4[56] = -128;
      zrd.a(this.c, var4, 0, var4.length);
      zrd.a(this.c, var3, var3.length);
      zjq.a((zjr)this.b, var2, 0, 16, var4, 0, var4.length);
      if (!zand.a(var4, var3, var3.length)) {
         throw new CellsException(2, "Invalid password.");
      }
   }

   public boolean a(int var1) {
      byte[] var3 = new byte[64];

      for(int var4 = 0; var4 < 5; ++var4) {
         var3[var4] = this.a[var4];
      }

      var3[5] = (byte)(var1 >>> 0 & 255);
      var3[6] = (byte)(var1 >>> 8 & 255);
      var3[7] = (byte)(var1 >>> 16 & 255);
      var3[8] = (byte)(var1 >>> 24 & 255);
      var3[9] = -128;
      var3[56] = 72;
      this.b = zjq.a(zcgd.b, zcgg.c);
      this.c = zrd.a(zcgh.a);
      zrd.a(this.c, var3, 0, var3.length);
      zrd.a(this.c, var3, 16);
      zcgf var2 = zjq.b(this.b, zcge.b, var3, 16, (byte[])null, 0);
      return var2 == zcgf.a;
   }

   public boolean a(byte[] var1, int var2, int var3, byte[] var4, int var5, int var6) {
      zcgf var7 = zjq.a(this.b, var1, var2, var3, var4, var5, var6);
      return var7 == zcgf.a;
   }

   public boolean b(int var1) {
      byte[] var2 = new byte[1024];
      int var3 = var1;

      boolean var4;
      int var5;
      for(var4 = true; var4 && var3 != 0; var3 -= var5) {
         var5 = Math.min(var3, var2.length);
         var4 = this.a(var2, 0, var5, var2, 0, var5);
      }

      return var4;
   }
}
